// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
// import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObject;
// import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
// import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
// import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "SQLServerInsertStatement.h"
#include "../SQLServerTop.h"
#include "../SQLServerOutput.h"
#include "../../visitor/SQLServerASTVisitor.h"
#include "../../../../../utils/listTran.h"
#include "../../../../ast/statement/SQLExprTableSource.h"
#include "../../../../ast/statement/SQLSelect.h"

SQLServerInsertStatement::SQLServerInsertStatement()
{
  dbType = DbType_ptr(new DbType(&DbType::sqlserver));
}

void SQLServerInsertStatement::cloneTo(SQLServerInsertStatement_ptr x)
{
  SQLInsertStatement::cloneTo(x);
  x->defaultValues = defaultValues;
  if (top != nullptr)
  {
    x->setTop(std::dynamic_pointer_cast<SQLServerTop>(top->clone()));
  }
  if (output != nullptr)
  {
    x->setOutput(std::dynamic_pointer_cast<SQLServerOutput>(output->clone()));
  }
}

// @Override
void SQLServerInsertStatement::accept0(SQLASTVisitor_ptr visitor)
{
  this->accept0(std::dynamic_pointer_cast<SQLServerASTVisitor>(visitor));
}

// @Override
void SQLServerInsertStatement::accept0(SQLServerASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLServerInsertStatement)))
  {
    this->acceptChild(visitor, getTop());
    this->acceptChild(visitor, getTableSource());
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLExpr, SQLObject>(getColumns());
    this->acceptChild(visitor, tmp1);
    this->acceptChild(visitor, getOutput());
    SQLObject_list_ptr tmp2 = ListTran::tran_class<SQLInsertStatement_ValuesClause, SQLObject>(getValuesList());
    this->acceptChild(visitor, tmp2);
    this->acceptChild(visitor, getQuery());
  }

  visitor->endVisit(SharedObject(SQLServerInsertStatement));
}

BOOL_ptr SQLServerInsertStatement::isDefaultValues()
{
  return defaultValues;
}

void SQLServerInsertStatement::setDefaultValues(BOOL_ptr defaultValues)
{
  this->defaultValues = defaultValues;
}

SQLServerOutput_ptr SQLServerInsertStatement::getOutput()
{
  return output;
}

void SQLServerInsertStatement::setOutput(SQLServerOutput_ptr output)
{
  this->output = output;
}

SQLServerTop_ptr SQLServerInsertStatement::getTop()
{
  return top;
}

void SQLServerInsertStatement::setTop(SQLServerTop_ptr top)
{
  this->top = top;
}

SQLObject_ptr SQLServerInsertStatement::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLServerInsertStatement>(new SQLServerInsertStatement());
  std::shared_ptr<SQLServerInsertStatement> x = std::dynamic_pointer_cast<SQLServerInsertStatement>(clone_tmp);
  // SQLServerInsertStatement x = new SQLServerInsertStatement();
  cloneTo(x);
  return x;
}
